import { userInfoAPI } from "@/http/userInfo";
import { defineStore } from "pinia";
import type { State } from "../type";

const useUserStore = defineStore("User", {
  state: (): State => ({
    id: 0,
    imageUrl: "",
    name: "",
    sex: "",
    department: "",
    identity: "",
    email: "",
    account: "",
    status: 0,
    createTime: "",
  }),
  actions: {
    async userInfo() {
      let account = localStorage.getItem("account") ?? "";
      const res = await userInfoAPI(null, account);
      this.id = res[0].id;
      this.imageUrl = res[0].image_url;
      this.name = res[0].name;
      this.sex = res[0].sex;
      this.department = res[0].department;
      this.identity = res[0].identity;
      this.account = res[0].account;
      this.email = res[0].email;
      this.status = res[0].status;
      this.createTime = res[0].create_time;
    },
  },
  getters: {},
});
// {
//     persist: {
//       enabled: true,
//       key: "userinfo",
//       storage: localStorage,
//     },
//   }
export default useUserStore;
